package puziran.sofa.util;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class SofaSpringContext {
	private static ApplicationContext ctx = null;
	public static Object getBean(String beanName) {
		return getSpringContext().getBean(beanName);
	}

	public static ApplicationContext getSpringContext() {
		if (ctx == null) {
			try {
				ctx = new ClassPathXmlApplicationContext(
						"config/applicationContext-*.xml");
				System.out.println("spring容器启动成功。");
			} catch (Exception e) {
				e.printStackTrace();
				System.out.println("spring容器启动失败。");
			}
		}
		return ctx;
	}
}